package pl.net.csrv.helpers;

import java.io.UnsupportedEncodingException;
import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class MD5Helper {
	public static String calculateMD5(String inputText) throws NoSuchAlgorithmException, UnsupportedEncodingException {
		String result = null;
		MessageDigest md = MessageDigest.getInstance("MD5");
		md.reset();
		byte[] mdBytes = md.digest(inputText.getBytes("UTF-8"));
		BigInteger bigIntRes = new BigInteger(1, mdBytes);
		result = bigIntRes.toString(16);
		while (result.length() < 32) {
			result = "0" + result;
		}

		return result;
	}
}
